#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @Time : 2018/9/30 下午4:04
# @Author : Desunire
# @projectname : bzShop
# @name: serializers

from  rest_framework import serializers
from  rest_framework.validators import UniqueTogetherValidator


from .models import UserFav


class UserFavSerializer(serializers.ModelSerializer):
    user = serializers.HiddenField(
        default=serializers.CurrentUserDefault()
    )

    class Meta:
        model = UserFav
        validators = [
            UniqueTogetherValidator(
                queryset=UserFav.objects.all(),
                fields=('user', 'goods'),
                message='已经收藏过了',
            )
        ]
        # id 是了删除
        fields = ("user", "goods", "id")